package com.heima.test4;

class A {
    public void test1() {
        synchronized (this) {
            for (int i = 0; i < 100; i++) {
                System.out.println("打篮球" + i);
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    public synchronized void test2() {
        for (int i = 0; i < 100; i++) {
            System.out.println("吃烤鸭" + i);
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Demo01 {
    public static void main(String[] args) {
        A a = new A();

        new Thread(()->{
            a.test2();
        }).start();
        new Thread(()->{
            a.test1();
        }).start();
    }
}
